<template>
    <div class="programModify">
        <el-form 
            ref="ruleForm" 
            label-width="100px"
            :model="ruleForm">
            <el-form-item label="商品名称">
                <el-input v-model="ruleForm.name"></el-input>
            </el-form-item>
            <el-upload
                class="upload-demo"
                action="https://www.yyjpai.com/index/operate/uploadsImg"
                :on-success=handleAvatarSuccess
                :file-list="fileList"
                name="file"
                list-type="picture">
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
            </el-upload>
            <el-form-item label="日产出上线">
                <el-input v-model="ruleForm.prizeUpperLimit"></el-input>
            </el-form-item>
            <el-form-item label="最小概率" prop="sectionMin">
                <el-input v-model="ruleForm.sectionMin"></el-input>
            </el-form-item>
            <el-form-item label="最大概率" prop="sectionMax">
                <el-input v-model="ruleForm.sectionMax"></el-input>
            </el-form-item>
            <el-form-item label="数量">
                <el-input v-model="ruleForm.number"></el-input>
            </el-form-item>
            <el-form-item label="商品类型">
                <el-select v-model="ruleForm.prizetype" placeholder="请选择商品类型">
                    <el-option label='请选择' value='' ></el-option>
                    <el-option label='红包' value='红包' ></el-option>
                    <el-option label='实物' value='实物' ></el-option>
                    <el-option label='金币' value='金币' ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="排序">
                <el-input v-model="ruleForm.sort"></el-input>
            </el-form-item>
            
        </el-form>
       <el-button @click="submitForm('ruleForm')" size="medium" class="addSubimit">提交</el-button>
    </div>
</template>
<script>
import { AddData } from "@/assets/js";
export default {
  data() {
    return {
      options: [], //下拉
      urlSize: 1, //上传图片数量
      fileList: [], //图片数组
      ruleForm: {
        //下拉选中
        logo: this.logo,
        name: this.name,
        prizeUpperLimit: this.limit,
        sectionMin:this.sectionMin,
        sectionMax:this.sectionMax,
        number: this.number,
        prizetype: this.prizetype,
        sort: this.sort
      }
    };
  },
  methods: {
    handleAvatarSuccess(res, file) {
      //上传成功之后
      this.ruleForm.logo = file.response.data.logo;
    },
    submitForm: function(e) {
      //点击提交
      var data = {
        id: this.id,
        logo: this.ruleForm.logo ? this.ruleForm.logo : this.logo,
        name: this.ruleForm.name ? this.ruleForm.name : this.name,
        prizeUpperLimit: this.ruleForm.prizeUpperLimit ? this.ruleForm.prizeUpperLimit : this.limit,
        sectionMin: this.ruleForm.sectionMin  ? this.ruleForm.sectionMin : this.sectionMin,
        sectionMax: this.ruleForm.sectionMax  ? this.ruleForm.sectionMax : this.sectionMax,
        number: this.ruleForm.number ? this.ruleForm.number : this.number,
        prizetype: this.ruleForm.prizetype  ? this.ruleForm.prizetype : this.prizetype,
        sort: this.ruleForm.sort ? this.ruleForm.sort : this.sort
      };
      AddData(this, e, data, "lottery_draw/editPrize");
    }
  },
  props: ["id", "name","sort","logo","prizetype", "number","sectionMin","sectionMax","limit"]
};
</script>

